import Vue from "vue";
import Router from "vue-router";
// import { basicData } from './modules/basic_data'
// import { deviceManagement } from './modules/device_management'
// import { deviceNetworking } from './modules/device_ntworking'
// import { productionManagement } from './modules/production_management'
// import { purchasingManagement } from './modules/purchasing_management'
// import { qualityAssurance } from './modules/quality_assurance'
// import { salesManagement } from './modules/sales_management'
// import { system } from './modules/system'
// import { warehouseManagement } from './modules/warehouse_management'
import { bulletinBoard } from "./modules/data_board";
// import { crmManage } from './modules/crm_manage'
// import { workshopWork } from './modules/workshop_work'
Vue.use(Router);
/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
    meta: {
      title: "登录",
      roles: ["admin", "editor"],
    },
  },

  {
    path: "/reload",
    name: "Reload",
    hidden: true,
    component: () => import("@/views/Reload.vue"),
    meta: {
      roles: ["admin", "editor"],
    },
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
    meta: {
      roles: ["admin", "editor"],
    },
  },
  //   {
  //   path: '/eqMaintenance',
  //   component: () => import('@/views/eqMaintenance'),
  //   hidden: true,
  //   meta: {
  //     roles: ['admin', 'editor']
  //   }
  // },

  {
    path: "",
    component: Layout,
    redirect: "/dashboard",
    meta: { title: "初始化信息", icon: "el-icon-user-solid", roles: ["admin"] },
    children: [
      {
        path: "companyInformation",
        name: "CompanyInformation",
        hidden: false,
        component: () => import("@/views/admin/company"),
        meta: { title: "公司信息", icon: "icon-shouye", affix: false },
      },
      {
        path: "menu",
        name: "Menu",
        hidden: false,
        component: () => import("@/views/admin/menu"),
        meta: { title: "菜单列表", icon: "icon-xitongshezhi", affix: false },
      },
      {
        path: "menuPower",
        name: "MenuPower",
        hidden: false,
        component: () => import("@/views/admin/MenuPower"),
        meta: { title: "菜单权限", icon: "icon-xitongshezhi", affix: false },
      },
    ],
  },
  {
    path: "/exp",
    component: Layout,
    redirect: "/experience",
    meta: { title: "经验数据", icon: "el-icon-s-claim", roles: ["admin"] },
    children: [
      {
        path: "addExperience",
        name: "addExperience",
        hidden: false,
        component: () => import("@/views/exp/register"),
        meta: { title: "数据登记", icon: "el-icon-edit", affix: false },
      },
      {
        path: "selExperience",
        name: "selExperience",
        hidden: false,
        component: () => import("@/views/exp/answer"),
        meta: { title: "数据查询", icon: "el-icon-search", affix: false },
      },
    ],
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    meta: {
      title: "主页",
      name: "Dashboard",
      roles: ["admin", "editor"],
    },
    hidden: true,
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        hidden: false,
        component: () => import("@/views/dashboard/index"),
        meta: { title: "企业主页", icon: "icon-zuzhijiagou", affix: true },
      },
    ],
  },
  bulletinBoard,

  // {
  //   path: '/loading',
  //   component: Layout,
  //   children: [{
  //     path: 'loading',
  //     name: 'Loading',
  //     hidden: true,
  //     component: () => import('@/components/Loading'),
  //     meta: { title: 'Loading', icon: 'el-icon-loading', affix: true }
  //   }]
  // },
  // system,
  // basicData,
  // deviceManagement,
  // deviceNetworking,
  // productionManagement,
  // workshopWork,
  // qualityAssurance,
  // purchasingManagement,
  // crmManage,
  // salesManagement,
  // warehouseManagement,
  // bulletinBoard,
  // {
  //   path: '*',
  //   redirect: '/404',
  //   hidden: true,
  //   meta: {
  //     roles: ['admin', 'editor']
  //   }
  // }
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    mode: process.env.NODE_ENV === "development" ? "history" : "hash", // 浏览器模式 : 服务模式
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
